import java.util.Scanner;

public class text {
    //输入一个非负整数，输出它的每一位相加的和
    public static void main(String[] args) {
        System.out.println(sum2(1729));

    }

    public static int sum2(int num) {
        int sum=0;
        if(num==1){
            return num;
        }else{
           return sum2(num/10)+num%10;


        }

    }
    //递归实现1+...+n的和
    public static void main5(String[] args) {
        System.out.println(sum(10));

    }
    public static int sum(int num){
        if(num == 1){
            return num;
        }
        return num+sum(num-1);
    }
    //按顺序打印数字的每一位
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        print(num);
    }
    public static void print(int n){
            if(n<10){
                System.out.println(n);
                return;
            }
            print(n/10);
            System.out.println(n%10);
    }
    public static int fac(int n ){
        if(n == 1){
            return 1;
        }else {
            int tmp = n*fac(n-1);
            return tmp;
        }
    }
    public static void main3(String[] args) {
        //递归实现n的阶乘
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fac(n));

    }
    public static void main2(String[] args) {
        //模拟登录
        int count = 3;//有三次登录机会
        while(count!=0){
            System.out.println("请输入密码，你有"+count+"次机会");
            Scanner scanner = new Scanner(System.in);
            String pastword = scanner.nextLine();//读取一行，遇到空格不会停下
            if(pastword.equals("123456")){
                System.out.println("密码正确");
                break;
            }else {
                count--;
                System.out.println("密码输入错误，你还有"+count+"次机会!"+"刚刚输入的密码是"+pastword);

            }

        }

    }
    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
    public static void main1(String[] args) {
        double sum = 0;
        int flag = 1;
        for (int i = 1; i < 101; i++) {
            sum += flag*1.0/i;
            flag = -flag;
        }
        System.out.println(sum);

    }
}
